<?php $this->load->view('header', $head);?>

<div data-role="page" id="create-poll">
	<div data-role="header">
		<h1>설문하기</h1>
		<a href="<?=site_url()?>" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
	</div><!-- /header -->
	<div data-role="content">
		<?=form_open('ajax/create_vote', array('class' => 'ajax-form'))?>
			<ul data-role="listview" <?=$this->agent->is_mobile()?'':'data-inset="true"'?>>
				<li data-role="list-divider">
					설문정보
				</li>
				<li data-role="fieldcontain">
					<p>제목: <?= $poll->title ?></p>
					<p>분류: <?= $poll->category ?></p>
					<p>키워드: <?= $poll->keyword ?></p>
					<p>작성자: <?= $username->name?></p>
					<p>설문기간: <?= $poll->poll_start.' - '.$poll->poll_end ?></p>
					
				</li>
				<!-- /question -->
				<li data-role="list-divider">
					설문문항
					<P></P>
				</li>
				<li>
				<p>
				<input type="hidden" name="poll_id" id="poll_id" value="<?=$poll->id?>" />
				<?php
					
					$cnt = 0;
					foreach($poll->questions as $item){
						$cnt++;
						// name & id = text-short-'question_id'
						if($item->type == 'text-short'){?>
							<label for="answers-<?=$cnt?>"><?=$cnt?>. <?=$item->title?></label>
    						<input type="text" name="answers-<?=$cnt?>" id="answers-<?=$cnt?>" value=""  />
						<?}
						// name & id = textarea-'question_id'
						if($item->type == 'text-long'){?>
							<label for="answers-<?=$cnt?>"><?=$cnt?>. <?=$item->title?></label>
							<textarea name="answers-<?=$cnt?>" id="answers-<?=$cnt?>"></textarea>
						<?}	
						// name = radio-choice-'question_id'
						// id = radio-choice-'count_number'
						// value = 'count_number'
						if($item->type == 'choose'){
							$cnt_option = 1;?>
							<fieldset data-role="controlgroup">
							<legend><?=$cnt?>. <?=$item->title?></legend>
								<?
									$cnt_option = 1;
									foreach($item->options as $option){?>
											<input type="radio" name="answers-<?=$cnt?>" id="radio-choice-<?=$cnt_option?>" value="<?=$cnt_option?>" <?=count($item->options)==1 ? "checked='true'":""?> />
						     				<label for="radio-choice-<?=$cnt_option?>"><?=$option?></label>
										<?$cnt_option++;
									}
								?>
							</fieldset>
						<?}
						// name & id = select-choice-'question_id'
						// value = 'count_number'
						if($item->type == 'select'){
							$cnt_option = 1;?>
							<label for="answers-<?=$cnt?>" class="select"><?=$cnt?>. <?=$item->title?></label>
							<select name="answers-<?=$cnt?>" id="answers-<?=$cnt?>">
								<?
									foreach($item->options as $option){?>
											<option value="<?=$cnt_option?>"><?=$option?></option>
									<?}
								?>
							</select>
						<?}
					
					}?>
				</p>	
				</li>
				<li class="ui-body ui-body-b">
					<fieldset class="ui-grid-a">
						<div class="ui-block-a">
							<button type="reset" data-theme="d">
								초기화
							</button>
						</div>
						<div class="ui-block-b">
							<button type="submit" data-theme="a">
								작성하기
							</button>
						</div>
					</fieldset>
				</li>
			</ul>
			<?=validation_errors()?>
		<?=form_close()?>
	</div><!-- /content -->
</div>
	<div data-role="footer">&nbsp;</div>
</div><!-- /page page-add-question -->

<?php $this->load->view('footer'); ?>